package com;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pojo.VolOrg;
import jdk.nashorn.internal.objects.annotations.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: fanyouzhao
 * @date: 10:19 2021/6/29
 */
public class GetAll {
    public static List<VolOrg> getVo(int page){
        String url = "http://sczyz.org.cn/apiv2/zysc/group/groupByCity";
        String parms = "page="+page+"&size=200";
        String s = HttpRequestUtils.sendGet(url, parms);
        JSONObject jsonObject = JSONObject.parseObject(s);
        JSONArray dataList = jsonObject.getJSONArray("data");
        ArrayList<VolOrg> volOrgs = new ArrayList<>();
        for (int i = 0; i < dataList.size(); i++) {
            JSONObject tempVo = dataList.getJSONObject(i);
            Integer id = Integer.valueOf(tempVo.getString("id"));
            String username = tempVo.getString("title");
            Integer volunteers = Integer.valueOf(tempVo.getString("volunteers"));
            Integer works = Integer.valueOf(tempVo.getString("works"));
            String sponsor = tempVo.getString("sponsor");
            String hour = tempVo.getString("hour");
            VolOrg volOrg = new VolOrg(id,username,"",
                    hour,sponsor,volunteers,works);
            volOrgs.add(volOrg);
        }
        return volOrgs;
    }
}
